package com.xn.coursed.commen;

import com.xn.coursed.pojo.entity.Graph;
import org.springframework.stereotype.Component;

@Component
public class GraphUtil {

    public Graph init (){
        /**
         * 初始化图
         */
        Graph g=new Graph();
        g.setArc( new int[][]{
                {0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {2, 0, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 5, 0, 0, 7, 0, 0, 12, 6, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 3, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 7, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0},
                {0, 0, 0, 0, 6, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 12, 0, 0, 0, 6, 0, 11, 0, 5, 0, 0, 0, 0, 0, 0},
                {0, 0, 6, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 0, 0, 5},
                {0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 10, 0, 0, 9, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 7, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 7, 0, 8},
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 8, 0}
        });
        g.setVex(new  String[]{
                "福建农林大学蜂学学院教工之家", "蜂学学院", "国家蔬菜加工技术研发分中心",
                "园艺科技楼", "园艺学院设施农业教学实践基地", "作物科学学院", "中华名特优植物园",
                "田家炳楼", "福建农林大学后勤管理处", "宝玲楼", "创新楼", "禧强楼", "博学楼",
                "机电工程学院", "林学院", "湿地公园", "食品科学学院"
        });
        g.setVexNum(g.getVex().length);
        g.setEdgeNum(g.getArc().length);
        g.setDist(new int[g.getVexNum()]);
        g.setPreIndex(new int[g.getVexNum()]);
        for (int i = 0; i < g.getVexNum(); i++) {
            g.getDist()[i] = Integer.MAX_VALUE;
        }
        for (int i = 0; i < g.getVexNum(); i++) {
            g.getPreIndex()[i] = -1;
        }

        System.out.println("Graph initialized with " + g.getVex().length + " vertices.");
        System.out.println("Adjacency matrix:");
        return g;
    }
}
